import requests
import json

if __name__ == "__main__":
    # 指定url
    # url = 'https://movie.douban.com/j/chart/top_list?type=11&interval_id=100%3A90&action=&start=0&limit=20'
    # 将后面的参数封装到字典中
    url = 'https://movie.douban.com/j/chart/top_list'
    param = {
        'type': '11',
        'interval_id': '100:90',
        'action': '',
        'start': '0', #从库中第几个电影开始取
        'limit': '20'# 一次取多少部电影
    }

    # UA伪装
    headers = {
        'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35'
    }

    # 发送请求
    response = requests.get(url=url,params=param,headers=headers)
    list_data = response.json()

    fp = open('douban_ranking.json','w',encoding='utf-8')
    json.dump(list_data,fp,ensure_ascii=False)

    print('--豆瓣剧情电影排名--')
    print('------完--毕------')

